﻿#ifndef DBSERVICE_H
#define DBSERVICE_H

#include <QMutex>
#include <QObject>
#include <QSqlDatabase>

struct DBConnection
{
	QString strName;
	QString strType;
	QString strScheme;

	int iHostPort;
	QString strHostName;
	QString strUserName;
	QString strPassword;
};

class QDBService : public QObject
{
	Q_OBJECT

public:
	QDBService(QObject *parent = 0);
	~QDBService();
	

public:
	bool init();
	bool initDatabase(const DBConnection & stConnect);

public:
	QSqlQuery * select(const QString & SQL, bool & bExec);
	bool execSQL(const QString & SQL, QString & strMsg);
	bool execBatch(const QVariantList & listSQL, QString & strMsg);

private:
	static int iDbCount;
	QSqlDatabase db;
};

//序列化函数
QString operator << (QByteArray & arrData, QSqlQuery & query);
QString operator >> (QByteArray & arrData, QSqlQuery & query);

#endif // DBSERVICE_H
